package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.domain.ZjHntMaterialStore;
import com.ruoyi.zhgd.dto.ZjHntMaterialStoreDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.ZjHntMaterialStoreVo;
import com.ruoyi.zhgd.domain.bo.ZjHntMaterialStoreBo;
import com.ruoyi.zhgd.service.IZjHntMaterialStoreService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 料仓  自建-混凝土-料仓
 *
 * @author yhy
 * @date 2023-09-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/hntMaterialStore")
public class ZjHntMaterialStoreController extends BaseController {

    private final IZjHntMaterialStoreService iZjHntMaterialStoreService;

    /**
     * 查询料仓  自建-混凝土-料仓列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<ZjHntMaterialStoreVo> list(ZjHntMaterialStoreBo bo, PageQuery pageQuery) {
        return iZjHntMaterialStoreService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出料仓  自建-混凝土-料仓列表
     */
    @SaCheckLogin
    @Log(title = "料仓  自建-混凝土-料仓", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZjHntMaterialStoreBo bo, HttpServletResponse response) {
        List<ZjHntMaterialStoreVo> list = iZjHntMaterialStoreService.queryList(bo);
        ExcelUtil.exportExcel(list, "料仓  自建-混凝土-料仓", ZjHntMaterialStoreVo.class, response);
    }

    /**
     * 获取料仓  自建-混凝土-料仓详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<ZjHntMaterialStoreVo> getInfo(@NotNull(message = "主键不能为空")
                                               @PathVariable Long id) {
        return R.ok(iZjHntMaterialStoreService.queryById(id));
    }

    /**
     * 新增料仓  自建-混凝土-料仓
     */
    @SaCheckLogin
    @Log(title = "料仓  自建-混凝土-料仓", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZjHntMaterialStore bo) {
        return toAjax(iZjHntMaterialStoreService.insertByBo(bo));
    }

    /**
     * 修改料仓  自建-混凝土-料仓
     */
    @SaCheckLogin
    @Log(title = "料仓  自建-混凝土-料仓", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZjHntMaterialStore bo) {
        return toAjax(iZjHntMaterialStoreService.updateByBo(bo));
    }

    /**
     * 删除料仓  自建-混凝土-料仓
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "料仓  自建-混凝土-料仓", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iZjHntMaterialStoreService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 混凝土料仓列表
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/hntMaterialStoreList")
    public R hntMaterialStoreList(@RequestParam Map<String,Object> params,
                                  @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                                  @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils pageUtils = iZjHntMaterialStoreService.hntMaterialStoreList(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }


    /**
     * 获取每个拌合站的料仓名称、类型
     * @param params
     * @return
     */
    @GetMapping("/materialStoreType")
    public R selectMaterialStoreType(@RequestParam Map<String,Object> params){
        List<ZjHntMaterialStoreDto> zjHntMaterialStoreDtos = iZjHntMaterialStoreService.selectMaterialStoreType(params);
        return R.ok(zjHntMaterialStoreDtos);
    }
}
